package com.github.limit.context;

import com.github.limit.handler.AbstractLimitHandler;
import com.github.limit.holder.AbstractLimitAnnotationHolder;
import org.springframework.util.CollectionUtils;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;

/**
 * @author: wangdejun
 * @create: 2019-10-12 10:25
 **/
public class LimitContext {


    public boolean start(Method method) {


        List<Annotation> annotationList = AbstractLimitAnnotationHolder.getMethodAnnotations(method);
        if (CollectionUtils.isEmpty(annotationList)) {
            return true;
        }

        for (Annotation annotation : annotationList) {
            boolean flag = AbstractLimitHandler.getHandler(annotation).handler(annotation, method);
            if (!flag) {
                return false;
            }
        }
        return true;
    }


}
